{% extends "base.html" %}

{% block content %}
<h2 class="mb-4">用户列表</h2>
<a href="{{ url_for('add_user') }}" class="btn btn-primary mb-3">新增用户</a>

<table class="table table-striped">
    <thead>
    <tr>
        <th>ID</th>
        <th>姓名</th>
        <th>邮箱</th>
        <th>年龄</th>
        <th>操作</th>
    </tr>
    </thead>
    <tbody>
    {% for user in users %}
    <tr>
        <td>{{ user['id'] }}</td>
        <td>{{ user['name'] }}</td>
        <td>{{ user['email'] }}</td>
        <td>{{ user['age'] }}</td>
        <td>
            <a href="{{ url_for('edit_user', id=user['id']) }}" class="btn btn-sm btn-warning">编辑</a>
            <form action="{{ url_for('delete_user', id=user['id']) }}" method="post" class="d-inline">
                <button type="submit" class="btn btn-sm btn-danger"
                        onclick="return confirm('确定要删除该用户吗？')">删除</button>
            </form>
        </td>
    </tr>
    {% endfor %}
    </tbody>
</table>
{% endblock %}
